<template>
  <view class="header">
    <view class="tab">
      <view
        class="tabItem"
        v-for="item of items"
        :key="item.id"
        :class="[getClass(index, item.id)]"
        @click="change('index', item.id)"
      >
        <view class="tabBox">
          {{ item.name }}
          <view class="icon"></view>
        </view>

        <view class="num">{{ item.num }}</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    index: {
      type: Number,
      default: 0,
    },

    items: {
      type: Array,
      default() {
        return [];
      },
    },
  },

  data() {
    return {};
  },

  methods: {
    change(el, id) {
      if (id === this[el]) {
        return;
      }

      // this.$emit("change", id);
    },
  },

  computed: {
    getClass() {
      return (el, id) => {
        return id === el ? "on" : "";
      };
    },
  },
};
</script>

<style lang="less" scoped>
.tab {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  padding: 0;
  background: #fff;
}

.tabItem {
  position: relative;
  width: 33.33%;
  text-align: center;
  height: 100rpx;
  line-height: 100rpx;

  .icon {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 16rpx;
    height: 6rpx;
    background: #f0250e;
    display: none;
  }

  &.on {
    .text {
      font-size: 32rpx;
      color: #262626;
    }

    .icon {
      display: block;
    }
  }

  .text {
    position: relative;
    display: inline-block;
    font-size: 28rpx;
    color: #8c8c8c;
    transition: 0.3s all;
  }

  .num {
    position: absolute;
    left: 52%;
    top: 26%;
    margin-left: 30rpx;
    font-size: 18rpx;
    line-height: 1;

    /* #ifdef H5 */
    -webkit-transform: scale(0.7);
    transform: scale(0.7);
    -webkit-transform-origin: 0% 50%;
    transform-origin: 0% 50%;
    /* #endif */
  }
}

.tabBox {
  position: relative;
  display: inline-block;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  max-width: 100%;
}
</style>
